<template>
  <div>
    <van-form @submit="onSubmit">
      <div style="margin: 16px">
        <P class="wjmm">{{ denluwj.wanji }}</P>
      </div>
      <div style="margin: 16px">
        <h2>{{ denluwj.biaoq }}</h2>
      </div>
      <van-field
        v-model="username"
        name="用户名"
        :placeholder="denluwj.nametext" 
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        :placeholder="denluwj.pwdtext"
      />
      <div style="margin: 16px"><p><span @click="sjdl()">{{denluwj.text1}}</span><span @click="mimadl()">{{denluwj.text2}}</span></p></div>
      <div style="margin: 16px">
        <van-button class="beijing" block type="info" native-type="submit"
          >登录</van-button
        >
      </div>
      <div style="margin: 16px; font-size: 12px">
        <van-checkbox v-model="checkbox" shape="square" aria-checked="false">
          {{denluwj.tigkuan}}</van-checkbox
        >
      </div>
    </van-form>
  </div>
</template>
<script>
import api from "../../lib/api";
import { mapMutations } from "vuex";
export default {
  props: ["denluwj"],
  data() {
    return {
      username: "",
      password: "",
      checkbox: false,
    };
  },
  methods: {
    ...mapMutations(["login"]),
    onSubmit(values) {
      console.log(this.checkbox);
      if (this.checkbox == false) {
        alert("请勾选");
      } else if (this.username == "" || this.password == "") {
        alert('请输入');
      } else {
        api
          .post("/login", {
            username: this.username,
            password: this.password,
          })
          .then(res=> {
            console.log(res);
            this.login(res.data);
            this.$router.replace({
              name: "My",
            });
          });
        console.log("submit", values);
      }
    },
    sjdl() {
      this.$router.replace({
        name: "cellphone",
      });
    },
    mimadl() {
      this.$router.replace({
        name: "denlu",
      });
    }
  }
};
</script>
<style >
.beijing {
  background-color: orange;
  border: orange 1px solid;
}
.wjmm {
  text-align: right;
}
</style>